package br.com.puertorico.mecanismos.ui.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import br.com.puertorico.common.utils.Validate;

public class SenhaValidator extends BaseValidator implements Validator {

	@Override
	public void validate(FacesContext ctx, UIComponent comp, Object value)
			throws ValidatorException {

		String str = (value != null) ? (String) value : "";

		if (!str.isEmpty() && !Validate.validarSenha(((String) value))) {
			FacesMessage facesMsg = new FacesMessage(
					FacesMessage.SEVERITY_ERROR, "", getMessage(value));
			throw new ValidatorException(facesMsg);
		}
	}
}
